<script setup>
import { defineProps, defineEmits } from 'vue';

const props = defineProps({
  categories: {
    type: Array,
    required: true
  },
  activeCategory: {
    type: String,
    required: true
  },
  forumPosts: {
    type: Array,
    required: true
  }
});

const emit = defineEmits(['update:activeCategory']);

const setActiveCategory = (category) => {
  emit('update:activeCategory', category);
};
</script>

<template>
  <div class="categories-sidebar">
    <h3 class="sidebar-title">Categories</h3>
    
    <div class="categories-list">
      <div 
        v-for="category in categories" 
        :key="category.id"
        class="category-item"
        :class="{ 'active': activeCategory === category.id }"
        @click="setActiveCategory(category.id)"
      >
        <span class="category-icon">{{ category.icon }}</span>
        <span class="category-name">{{ category.name }}</span>
        <span class="category-count">{{ 
          category.id === 'all' 
            ? forumPosts.length 
            : forumPosts.filter(post => post.category === category.id).length 
        }}</span>
      </div>
    </div>
    
    <div class="forum-stats">
      <h3 class="sidebar-title">Forum Stats</h3>
      <div class="stat-item">
        <span class="stat-icon">👥</span>
        <span class="stat-label">Users</span>
        <span class="stat-value">3,245</span>
      </div>
      <div class="stat-item">
        <span class="stat-icon">📝</span>
        <span class="stat-label">Topics</span>
        <span class="stat-value">1,567</span>
      </div>
      <div class="stat-item">
        <span class="stat-icon">💬</span>
        <span class="stat-label">Replies</span>
        <span class="stat-value">12,890</span>
      </div>
    </div>
  </div>
</template>

<style scoped>
/* 侧边栏样式 */
.categories-sidebar {
  width: 300px;
  flex-shrink: 0;
}

.sidebar-title {
  font-size: 1.2rem;
  color: #333;
  margin-bottom: 20px;
  font-weight: 600;
}

.categories-list {
  background-color: #f8f8f8;
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 30px;
}

.category-item {
  display: flex;
  align-items: center;
  padding: 15px 20px;
  cursor: pointer;
  transition: all 0.3s;
  position: relative;
}

.category-item:not(:last-child) {
  border-bottom: 1px solid #eeeeee;
}

.category-item:hover {
  background-color: #f0f0f0;
}

.category-item.active {
  background-color: #edf9f5;
}

.category-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  background-color: #00c389;
}

.category-icon {
  margin-right: 12px;
  font-size: 1.2rem;
}

.category-name {
  flex-grow: 1;
  color: #333;
}

.category-count {
  background-color: #e4e4e4;
  color: #555;
  font-size: 0.85rem;
  padding: 3px 8px;
  border-radius: 10px;
  transition: all 0.3s;
}

.category-item.active .category-count {
  background-color: #00c389;
  color: white;
}

/* 统计信息样式 */
.forum-stats {
  background-color: #f8f8f8;
  border-radius: 10px;
  padding: 20px;
}

.stat-item {
  display: flex;
  align-items: center;
  margin-bottom: 15px;
}

.stat-item:last-child {
  margin-bottom: 0;
}

.stat-icon {
  margin-right: 10px;
  font-size: 1.1rem;
}

.stat-label {
  flex-grow: 1;
  color: #555;
}

.stat-value {
  font-weight: 600;
  color: #333;
}

@media (max-width: 1200px) {
  .categories-sidebar {
    width: 100%;
    margin-bottom: 30px;
  }
  
  .forum-stats {
    display: flex;
    justify-content: space-around;
  }
  
  .stat-item {
    margin-bottom: 0;
  }
}

@media (max-width: 768px) {
  .forum-stats {
    flex-direction: column;
  }
  
  .stat-item {
    margin-bottom: 15px;
  }
}
</style> 